import React, { Component } from 'react';
import qs from 'query-string' // 用于处理获取到的search数据， 这库得下载

const DetailData = [
    {id: "01", content: "你好，中国"},
    {id: "02", content: "你好，世界"},
    {id: "03", content: "你好，python"},
]
export default class Detail extends Component {
  render() {
    //   接收params参数
    // const {id,title} = this.props.match.params

    // 接收search参数, 参数会是"?id=01&title=消息1"的形式
    // const {search} = this.props.location
    // const {id, title} = qs.parse(search.slice(1)) // 处理search参数的格式
    
    // 接收state参数
    const {id, title} = this.props.location.state  || {}
    

    const findResult =DetailData.find((detailObj) => {
        return detailObj.id === id
    }) || {}

    return (
        <ul>
            <li>ID:{id}</li>
            <li>TITLE:{title}</li>
            <li>CONTENT:{findResult.content}</li>
        </ul>
    );
  }
}
